package com.example.personal.aiagent.xunfei.account.controller;

import java.util.stream.Collectors;

import com.example.personal.aiagent.xunfei.account.model.dto.AccountDTO;
import com.example.personal.aiagent.xunfei.account.model.vo.AccountRequest;
import com.example.personal.aiagent.xunfei.account.service.AccountService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.example.personal.aiagent.common.constant.Constants;
import com.example.personal.aiagent.common.model.vo.CommonListResponse;
import com.example.personal.aiagent.common.model.vo.SuccessResponse;
import com.example.personal.aiagent.common.util.RequestParamUtil;
import com.example.personal.aiagent.user.model.dto.UserDTO;
import com.example.personal.aiagent.user.model.vo.UserListResponse;
import com.example.personal.aiagent.user.model.vo.UserRequest;
import com.example.personal.aiagent.user.service.UserService;

import lombok.extern.slf4j.Slf4j;

/**
 * 账户Api
 */
@Controller
@RequestMapping("/account")
@Slf4j
public class AccountController {
    @Autowired
    private UserService userService;

    @Autowired
    private AccountService accountService;

    @ResponseBody
    @PostMapping("")
    public SuccessResponse add(@RequestBody @Validated AccountRequest request) {
        accountService.insertAccount(AccountDTO.voToDTO(request));
        return new SuccessResponse();
    }

    @ResponseBody
    @PutMapping("")
    public SuccessResponse modify(@RequestBody @Validated AccountRequest request) {
        accountService.updateAccount(AccountDTO.voToDTO(request));
        return new SuccessResponse();
    }

    @ResponseBody
    @DeleteMapping("/{id}")
    public SuccessResponse deleteByUserId(@PathVariable(name = "id") int userId) {
        accountService.deleteAccount(userId);
        return new SuccessResponse();
    }
}
